Total Complexity | 4 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import * as firebase from "firebase"; |
||
12 | |||
13 | export class AuthProvider { |
||
14 | public constructor( |
||
15 | public authAnonymous: AnonymousAuth, |
||
16 | public authEmail: EmailAuth, |
||
17 | public authFacebook: FacebookAuth, |
||
18 | public authGithub: GithubAuth, |
||
19 | public authGoogle: GoogleAuth, |
||
20 | public authPhone: PhoneAuth, |
||
21 | public authTwitter: TwitterAuth, |
||
22 | ) {} |
||
23 | |||
24 | public getProviderById(providerId: string): IAuthProvider | null { |
||
25 | switch (providerId) { |
||
26 | case "password": |
||
27 | return this.authEmail; |
||
28 | case "phone": |
||
29 | return this.authPhone; |
||
30 | case "facebook.com": |
||
31 | return this.authFacebook; |
||
32 | case "github.com": |
||
33 | return this.authGithub; |
||
34 | case "google.com": |
||
35 | return this.authGoogle; |
||
36 | case "twitter.com": |
||
37 | return this.authTwitter; |
||
38 | case "apple.com": |
||
39 | case "yahoo.com": |
||
40 | case "hotmail.com": |
||
41 | throw new Error(`Provider ${providerId} not implemented!`); |
||
42 | } |
||
43 | |||
44 | return null; |
||
45 | } |
||
46 | |||
47 | public getProviderByUser(user: firebase.User): IAuthProvider | null { |
||
48 | if (user.isAnonymous) { |
||
49 | return this.authAnonymous; |
||
50 | } |
||
51 | |||
52 | return this.getProviderById(user.providerId); |
||
53 | } |
||
55 |